/**
 * 
 */
package de.cbf.cam.dsa.model.entities;

import java.beans.PropertyChangeSupport;

import javax.persistence.Entity;
import javax.persistence.Transient;

import de.cbf.cam.dsa.model.entities.constants.Zones;
import de.cbf.cam.dsa.model.entities.items.Item;

/**
 * @author Nebelritter
 *
 */
@Entity
public class ArmorPart extends Item{
		
	/**
	 * @uml.property  name="rs" multiplicity="(0 -1)" dimension="1"
	 */
	private int[] rs= new int[Zones.zoneNames.length];	
	/**
	 * @uml.property  name="structure" multiplicity="(0 -1)" dimension="1"
	 */
	private int[] structure= new int[Zones.zoneNames.length];
	
	/**
	 * @uml.property  name="stars"
	 */
	private int stars=0;
	
	public static String PROPERTYNAME = "ArmorPart:";	
	/**
	 * @uml.property  name="propertyChangeSupport"
	 */
	public PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
//========================
//			constructors
//========================		
	/**
	 * 
	 */
	public ArmorPart() {
		
	}

//========================
//		   public methods
//========================




//========================
//	    standard methods
//========================
	@Override
	public String toString() {
		return name;
	}
//========================
//	 	   private methods
//========================

//========================
//	 	SHORT property access
//========================

	@Transient
	public int[] getRsZones() {
		return rs;
	}

	public void setRsZones(int[] rs) {
		this.rs=rs;
	}
	@Transient
	public int[] getStructureZones() {
		return rs;
	}
	
	public void setStructureZones(int[] structure) {
		this.structure=structure;
	}
	/**
	 * @return the rs
	 */
	@Transient
	public float getRs() {
		float result=0;
		for(int j=0;j<rs.length;j++){
			result +=rs[j]*Zones.zoneFactors[j];
		}
		result = result / Zones.rsFactor;		
		return result;
	}
	/**
	 * @return the rs
	 */
	public int getRs(int zone) {
		return rs[zone];
	}
	/**
	 * @return the be
	 */
	@Transient
	public float getBe() {
		float result =0;
		for(int j=0;j<Zones.zoneFactors.length;j++){
			result +=rs[j]*Zones.zoneFactors[j];
		}
		result = result / Zones.beFactor;	
		result = result - stars;
		return result;
	}
	/**
	 * @return the structure
	 */
	public int getStructure() {
		int result =0;
		for(int j=0;j<Zones.zoneFactors.length;j++){
			result +=structure[j];//*zoneFactors[j];
		}
//		float floatResult = result;
//		floatResult = floatResult / rsFactor;			
//		result+=Math.round(floatResult);
		return result;
	}
	public int getStructure(int zone) {
		return structure[zone];
	}
	
	public void setRS(int zone,int rs) {
		this.rs[zone]=rs;
	}
	
	public void setStructure(int zone,int structure) {
		this.structure[zone]=structure;
	}
//========================
//			getters
//========================
		
	/**
	 * @return
	 * @uml.property  name="stars"
	 */
	public int getStars() {
		return stars;
	}

//========================
//			setters
//========================
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"name",null,name);
	}
	
	/**
	 * @param rs
	 * @uml.property  name="rs"
	 */
	public void setRs(int[] rs) {
		this.rs = rs;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"rs",null,rs);
	}

	/**
	 * @param structure
	 * @uml.property  name="structure"
	 */
	public void setStructure(int[] structure) {
		this.structure = structure;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"structure",null,structure);
	}
	
	/**
	 * @param stars
	 * @uml.property  name="stars"
	 */
	public void setStars(int stars) {
		this.stars = stars;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"stars",null,stars);
	}	
}
